var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: {
    index: './src/main.js',
    vendor:"./src/vendor.js"
  },
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: '[name].js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      // {
      //   test: /\.(png|jpg|gif|svg)$/,
      //   loader: 'file-loader',
      //   options: {
      //     name: '[name].[ext]?[hash]'
      //   }
      // }
    ]
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      names: ['vendor', 'manifest']
    }),
    new webpack.SourceMapDevToolPlugin({
      filename: "[file].map",
      exclude : ["vendor.js","manifest.js"] //禁止库文件生成source-map。注意，不用再使用devtool: '#source-map'的配置项，不然此设置就被覆盖了
    }),
    // new HtmlWebpackPlugin({
    //   template: 'src/index.html'
    // })
  ],
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      'axios': 'axios/dist/axios.min.js'
    }
  },
  // externals:{
  //   "Vue":"Vue",
  //   'element-ui': 'element-ui'
  // },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    proxy: {
        '/common': {
          target: 'http://39.108.97.214:8088',
          secure: false
        }
      }
  },
  performance: {
    hints: false
  },
  // devtool: '#eval-source-map'
  // devtool: '#source-map'
}

if (process.env.NODE_ENV === 'production') {
  // module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}
